home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / ABox 1.9.5 / CPlus Files / ABOtherTopic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  14.6 KB  |  631 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABOtherTopic.c
  15.  
  16. NAME
  17.     ABOtherTopic.c, part of the ABox project source code,
  18.     responsible for handling the ABOtherTopic class stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                ttempel@monmouth.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <ttempel@monmouth.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     13 july 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     28-july-94    -    ty    -    1.0.6 -- removed cursor flipping from Load
  38.     10-apr-95    -    ty    -    added support for TeachText/SimpleText 'ttro'
  39.                             documents (but only as text, no pict processing)
  40.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  41.                             release and the associated Universal Headers from Apple:
  42.                             most methods that returned references now have "Ref" at
  43.                             the end of their methods names to prevent possible collisions
  44.                             with datatypes and classes of the same name (older versions
  45.                             of the compiler didn't have a problem with this).
  46.     25-oct-95    -    ty    -    changes for "const" usage under CW7; simplification of Boolean
  47.                             query methods
  48. */
  49.  
  50. /*===========================================================================*/
  51.  
  52. /*======= Segmentation directives ========*/
  53.  
  54. #ifdef USE_MANUAL_SEGMENTATION
  55. #pragma segment ty
  56. #endif
  57.  
  58. /*============ Header files ==============*/
  59.     
  60. #include     "ABOtherTopic.h"
  61. #include    "ABoxDefs.h"
  62. #include     "ABUCursor.h"
  63.  
  64.  
  65. /*=============== Globals ================*/
  66.  
  67. /*================ CODE ==================*/
  68.  
  69.  
  70. /*=============================== ABOtherTopic::ABOtherTopic ================================*/
  71. ABOtherTopic::ABOtherTopic(const FSSpec& inTopicFSSpec)
  72.     :    ABTopic(inTopicFSSpec)
  73. {
  74.     this->ResetSlideInfo();
  75.  
  76.     this->BlurbRef() = NULL;
  77.     this->FileTypeRef() = kABbadFileType;
  78.     this->TopicType() = ETopicType_OtherTopic;
  79. } // end ABOtherTopic
  80.  
  81.  
  82.  
  83.  
  84. /*=============================== ABOtherTopic::~ABOtherTopic ================================*/
  85. ABOtherTopic::~ABOtherTopic(void)
  86. {
  87.     if (this->HasBlurb())
  88.     {
  89.         delete this->BlurbRef();
  90.         this->BlurbRef() = NULL;
  91.     }
  92.     
  93. } // end ~ABOtherTopic
  94.  
  95.  
  96.  
  97.  
  98. /*=============================== ABOtherTopic::GetProperty ================================*/
  99. OSErr    ABOtherTopic::GetProperty(ABProperty prop, 
  100.                                 void *ptr, 
  101.                                 long *ptrSize)
  102. {
  103.     OSErr    error = noErr;
  104.     long    pSize;
  105.     
  106.     //    begin here...
  107.     
  108.     if (!ptr)
  109.         return kABPropertyNullStorage;
  110.     
  111.     switch (prop)
  112.     {
  113.         case    kABTopicIsFolder:
  114.                     *((Boolean *)ptr) = (this->FileTypeRef() == kABFolderFileType);
  115.                     pSize = kABTopicIsFolderSize;
  116.                     break;
  117.         case    kABTopicFileType:
  118.                     *((ABTopicFileType *)ptr) = this->FileTypeRef();
  119.                     pSize = kABTopicFileTypeSize;
  120.                     break;
  121.         default:
  122.                     error = kABOtherTopicSuperProperties::GetProperty(prop, ptr, ptrSize);
  123.                     break;
  124.     } // end switch block
  125.     
  126.     if (ptrSize && !error)
  127.         *ptrSize = pSize;
  128.     return error;
  129.     
  130. } // end GetProperty
  131.  
  132.  
  133.  
  134.  
  135.  
  136. /*=============================== ABOtherTopic::SetProperty ================================*/
  137. OSErr    ABOtherTopic::SetProperty(ABProperty prop, 
  138.                                 void *ptr, 
  139.                                 long ptrSize)
  140. {
  141.     OSErr            error = noErr;
  142.     
  143.     //    begin here...
  144.     
  145.     if (!ptr)
  146.         return kABPropertyNullStorage;
  147.     
  148.     switch (prop)
  149.     {
  150.         case    kABTopicIsFolder:
  151.                     error = kABPropertyReadOnly;
  152.                     break;
  153.  
  154.         default:
  155.                     error = kABOtherTopicSuperProperties::SetProperty(prop, ptr, ptrSize);
  156.                     break;
  157.     } // end switch block
  158.     
  159.     return error;
  160.     
  161. } // end SetProperty
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. /*=============================== ABOtherTopic::Resize ===============================*/
  170. //
  171. //    this function will rearrange and resize the picture and the
  172. //    text fields that appear on a slide.
  173. //
  174. //    This method will cause the current slide for the
  175. //    topic to resize by invoking that item's resize method.
  176. //
  177. //    is called by:
  178. //
  179. OSErr    ABOtherTopic::Resize (Rect const *field)
  180. {
  181.     OSErr    error = noErr;
  182.     Rect    box;
  183.     
  184.     //    begin here...
  185.     
  186.     error = ABTopic::Resize(field);
  187.     if (error == noErr)
  188.     {
  189.         box = *field;
  190.         if (this->HasBlurb())
  191.             error = this->BlurbRef()->SetProperty(kABObjectRect, &box, kABObjectRectSize);
  192.         else
  193.             error = paramErr;
  194.     } // endif else block
  195.     
  196.     return error;
  197. } // end of Resize
  198.  
  199.  
  200.  
  201.  
  202.  
  203. /*=============================== ABOtherTopic::OpenTopic ================================*/
  204. OSErr    ABOtherTopic::OpenTopic(void)
  205. {
  206.     OSErr        error = noErr;
  207.  
  208.     Handle        dataHandle = NULL;
  209.     short        blurbResID;
  210.     short        tempRefNum;
  211.     long        dataCount;
  212.     const long    headerOffset = 512;
  213.     const long    thirtyTwoKLimit = 32767;
  214.     
  215.     //    begin here...
  216.     
  217.     //    now load the data and create a "resource" outta it...
  218.     //
  219.     ABUCursor::WatchCursor();
  220.     if (this->HasBlurb())
  221.     {
  222.         delete this->BlurbRef();
  223.         this->BlurbRef() = NULL;
  224.     }
  225.     
  226.     //    now...if the "fileType" is something like kABfolderFileType
  227.     //    then we're dealing with a folder, and we should just display
  228.     //    the standard folder message (which comes from a resource).
  229.     //    If, however, the fileType is something else we'd be interested
  230.     //    in, then we need to create some storage.
  231.     if (!this->HasFSSpecPointer() && !this->IsFolder())
  232.     {
  233.         ABUCursor::ArrowCursor();
  234.         return resNotFound;
  235.     }
  236.         
  237.     switch (this->GetFileType())
  238.     {
  239.         case    kABFolderFileType:
  240.                 //    yup, it's a folder, so set resourceID to use
  241.                 //
  242.                 //    switch to the ABox resource file first...
  243.                 (void)this->UseTopicResFile();
  244.     
  245.                 blurbResID = kABfolderTextSlide;
  246.                 this->BlurbRef() = new ABText;
  247.                 break;
  248.         case    kABbadFileType:
  249.                 //    huh? this shouldn't happen...
  250.                 ABUCursor::ArrowCursor();
  251.                 return resNotFound;
  252.                 break;
  253.         case    kABPictResource:
  254.         case    kABTextResource:
  255.         case    kABTeachTextReadOnly:
  256.                 //    something else, so we need to create some storage
  257.                 
  258.                 //    open the file...
  259.                 error = ::FSpOpenDF (this->FSSpecPointerRef(), fsRdPerm, &tempRefNum);
  260.                 if (error)
  261.                     return error;
  262.                 
  263.                 //    find out how large
  264.                 error = ::GetEOF(tempRefNum, &dataCount);
  265.                 if (error)
  266.                 {
  267.                     ::FSClose (tempRefNum);
  268.                     ABUCursor::ArrowCursor();
  269.                     return error;
  270.                 } // end if
  271.                 
  272.                 //    create some storage...
  273.                 dataHandle = ::NewHandle (dataCount);
  274.                 error = ::MemError();
  275.                 if (error)
  276.                 {
  277.                     ::FSClose (tempRefNum);
  278.                     ABUCursor::ArrowCursor();
  279.                     return error;
  280.                 } // end if
  281.             
  282.                 //    read the file's data into memory
  283.  
  284.                 switch (this->GetFileType())
  285.                 {
  286.                     case    kABFolderFileType:
  287.                             //    this shouldn't get here...then again
  288.                             error = resNotFound;
  289.                             break;
  290.                     case    kABPictResource:
  291.                             //    read a PICT file:
  292.                             //    advance past the 512 byte header of a PICT file
  293.                             //
  294.                             this->BlurbRef() = new ABPict;
  295.                             error = ::SetFPos ( tempRefNum, fsFromStart, headerOffset );
  296.                             dataCount -= headerOffset;
  297.                             ::SetHandleSize (dataHandle, dataCount);
  298.                             break;
  299.                     case    kABTeachTextReadOnly:
  300.                             //    added support for the 'ttro' teach-/simple-text read
  301.                             //    only text document. We must do this because the file
  302.                             //    type gets mapped to a resource type
  303.                             this->FileTypeRef() = kABTextResource;
  304.                             
  305.                             //    fall-thru is intentional!
  306.                             
  307.                     case    kABTextResource:
  308.                             //    limit the stuff read to 32K!
  309.                             this->BlurbRef() = new ABText;
  310.                             if (dataCount > thirtyTwoKLimit)
  311.                             {
  312.                                 dataCount = thirtyTwoKLimit;
  313.                                 ::SetHandleSize (dataHandle, dataCount);
  314.                             } // end if block
  315.                             
  316.                             break;
  317.                     default:
  318.                             //    huh?
  319.                             error = resNotFound;
  320.                             break;
  321.                 } // end switch block
  322.                         
  323.                 if (error || this->DoesntHaveBlurb())
  324.                 {
  325.                     if (!error && this->DoesntHaveBlurb())
  326.                         error = ::MemError();
  327.                     ::FSClose (tempRefNum);
  328.                     ::DisposHandle(dataHandle);
  329.                     ABUCursor::ArrowCursor();
  330.                     return error;
  331.                 } // end if
  332.                 
  333.                 //    now read the data into the handle and close up the file
  334.                 ::HLock(dataHandle);
  335.                 error = ::FSRead ( tempRefNum, &dataCount, *dataHandle);
  336.                 ::HUnlock (dataHandle);
  337.                 (void)::FSClose (tempRefNum);
  338.                 if (error)
  339.                 {
  340.                     ::DisposHandle(dataHandle);
  341.                     ABUCursor::ArrowCursor();
  342.                     return error;
  343.                 } // end if
  344.             
  345.                 //    synthesize the resource so the ABResource object can use it properly
  346.                 //    <pretty sneaky, eh?>
  347.                 //
  348.                 //    switch to the resource file (hopefully, the application one)
  349.                 if (!this->HasFileRefNum())
  350.                     ::UseResFile(this->GetFileRefNum());
  351.             
  352.                 blurbResID = ::UniqueID(this->GetFileType());
  353.                 ::AddResource (dataHandle, 
  354.                             this->GetFileType(), 
  355.                             blurbResID,
  356.                             kABSyntheticResourceName);
  357.                 error = ::ResError();
  358.                 if (error)
  359.                 {
  360.                     ABUCursor::ArrowCursor();
  361.                     return error;
  362.                 } // end if block
  363.     
  364.                 //    now shove the resource into the ABResource object
  365.                 error = this->BlurbRef()->SetProperty (kABResourceHandle, &dataHandle, kABResourceHandleSize);
  366.                 break;
  367.         default:
  368.                 //    huh? we should never get here...
  369.                 error = resNotFound;
  370.                 break;
  371.     } // end switch block
  372.     
  373.     if (error == noErr)
  374.         if (this->HasBlurb())
  375.             //    set the resource ID for the ABResource object
  376.             error = this->BlurbRef()->SetProperty (kABResourceResID, &blurbResID, kABResourceResIDSize);
  377.         else
  378.             error = ::MemError();
  379.             
  380.  
  381.     ABUCursor::ArrowCursor();
  382.     
  383.     return error;
  384. } // end OpenTopic
  385.  
  386.  
  387.  
  388.  
  389.  
  390. /*=============================== ABOtherTopic::CloseTopic ================================*/
  391. OSErr    ABOtherTopic::CloseTopic(void)
  392. {
  393.     OSErr        error = noErr;
  394.     Handle        resHandle;
  395.     short        resAttributes;
  396.     
  397.     //    begin here...
  398.     ABUCursor::WatchCursor();
  399.  
  400.     if (this->HasBlurb())
  401.         error = this->BlurbRef()->GetProperty (kABResourceHandle, &resHandle, NULL);
  402.         
  403.     if ((error == noErr) && resHandle && this->HasBlurb())
  404.     {
  405.         if (!this->IsFolder())
  406.         {
  407.             short oldResFile = this->UseTopicResFile();
  408.     
  409.             resAttributes = ::GetResAttrs(resHandle);
  410.             ::RmveResource (resHandle);
  411.             error = ::ResError();
  412.             if (resAttributes & resChanged)
  413.             {
  414.                 resAttributes ^= resChanged;
  415.                 ::SetResAttrs (resHandle, resAttributes);
  416.                 error = ::ResError();
  417.             } // end if block
  418.             
  419.             ::RmveResource (resHandle);
  420.             ::UpdateResFile (this->GetFileRefNum());
  421.             error = ::ResError();
  422.             ::DisposHandle ((Handle)resHandle);
  423.             resHandle = NULL;
  424.             error = this->BlurbRef()->SetProperty (kABResourceHandle, &resHandle, kABResourceHandleSize);
  425.             
  426.             ::UseResFile(oldResFile);
  427.             
  428.         } // end if block
  429.         
  430.         delete this->BlurbRef();
  431.         this->BlurbRef() = NULL;
  432.     } // end if block
  433.  
  434.     ABUCursor::ArrowCursor();
  435.     return error;
  436. } // end CloseTopic
  437.  
  438.  
  439.  
  440.  
  441.  
  442. /*=============================== ABOtherTopic::DoLoad ===============================*/
  443. //
  444. OSErr    ABOtherTopic::DoLoad (void)
  445. {
  446.     return noErr;
  447.     
  448. }    //    end of function DoLoad
  449.  
  450.  
  451.  
  452.  
  453.  
  454. /*=============================== ABOtherTopic::DoCheckSlides ===============================*/
  455. //
  456. //    This function checks a file's type and will return a zero value
  457. //    if it is not acceptable, or a non-zero valuee(1) to indicate
  458. //    that it is acceptable.
  459. //
  460. //    is called by:
  461. //
  462. short    ABOtherTopic::DoCheckSlides (void)
  463. {
  464.     const short        badCount = 0;
  465.     short            count = badCount;
  466.     FInfo            fileInfo;
  467.     OSErr            error = noErr;
  468.     
  469.     const Boolean    resolvedAliasChains = true;
  470.     Boolean            targetIsFolder = false;
  471.     Boolean            wasAliased = false;
  472.     
  473.     //    begin here...
  474.     
  475.     
  476.     if (this->DoesntHaveFSSpecPointer())
  477.         return badCount;
  478.     
  479.     //    i can't assume that the alias has been resolved, nor do
  480.     //    i want to at this point. What i'm really concerned with is
  481.     //    whether the FSSpecPtr describes a file (which will be useful),
  482.     //    or a folder (which will also be useful). Since FSpGetFInfo()
  483.     //    can't tell me if the file is/isn't a folder, i'll use
  484.     //    ResolveAliasFile and only pay attention to the targetIsFolder
  485.     //    return value.
  486.     
  487.     error = ::ResolveAliasFile (this->FSSpecPointerRef(), 
  488.                                 resolvedAliasChains, 
  489.                                 &targetIsFolder, 
  490.                                 &wasAliased);
  491.     if (error)
  492.         return badCount;
  493.         
  494.     if (targetIsFolder)
  495.     {
  496.         //    so, the FSSpecPtr described a folder
  497.         this->FileTypeRef() = kABFolderFileType;
  498.         //this->FileRefNumRef() = ::CurResFile();
  499.         count = 1;
  500.     } else {
  501.         //    well, the FSSpecPtr described a file, but
  502.         //    what kind? Let's try to find out initially
  503.         //    by examining the fileType code that the system
  504.         //    returns to us
  505.         //
  506.         
  507.         error = ::FSpGetFInfo (this->FSSpecPointerRef(), &fileInfo);
  508.         if (error == noErr)
  509.         {
  510.             //    check the file's type and decide then and there...save the
  511.             //    filetype into our member field "fileType" if it is acceptable
  512.             switch (fileInfo.fdType)
  513.             {
  514.                 case    kABPictResource:
  515.                 case    kABTextResource:
  516.                 case    kABTeachTextReadOnly:
  517.                         //    this is a good topic!
  518.                         this->FileTypeRef() = fileInfo.fdType;
  519.                         count = 1;
  520.                         break;
  521.                 default:
  522.                         //    well...it _could_ be a movie, but let someone
  523.                         //    else figure that one out! (Actually, that will
  524.                         //    be taken care of by our caller, so don't worry!)
  525.                         break;
  526.             } // end switch block
  527.         }
  528.         
  529.     } // end if block
  530.     
  531.     return count;
  532. }    //    end of function DoCheckSlides
  533.  
  534.  
  535.  
  536.  
  537. /*=============================== ABOtherTopic::Draw ================================*/
  538. OSErr    ABOtherTopic::Draw(WindowPtr window)
  539. {
  540.     OSErr        error = noErr;
  541.     
  542.     //    begin here...
  543.     //
  544.     short        oldResFile = this->UseTopicResFile();
  545.     
  546.     if (this->HasBlurb())
  547.     {
  548.         error = ABObject::Draw(window); 
  549.         if (!error)
  550.             error = this->BlurbRef()->Draw(window);
  551.         
  552.     } // end if else block
  553.     
  554.     ::UseResFile (oldResFile);
  555.     
  556.     return error;
  557.     
  558. } // end Draw
  559.  
  560.  
  561.  
  562.  
  563.  
  564. /*=============================== ABOtherTopic::Update ================================*/
  565. OSErr    ABOtherTopic::Update(WindowPtr window)
  566. {
  567.     OSErr        error = noErr;
  568.     
  569.     short        oldResFile = this->UseTopicResFile();
  570.     
  571.     //    begin here...
  572.     //
  573.     if (this->HasBlurb())
  574.     {
  575.         error = this->BlurbRef()->Update(window);
  576.     } else {
  577.         error = noErr;
  578.     } // end if else block
  579.     
  580.     ::UseResFile (oldResFile);
  581.     
  582.     return error;
  583. } // end Update
  584.  
  585.  
  586.  
  587.  
  588. /*=============================== ABOtherTopic::Event ================================*/
  589. Boolean    ABOtherTopic::Event(EventRecord *eventRec)
  590. {
  591.     Boolean    test = false;
  592.     
  593.     //    begin here...
  594.     //
  595.     short        oldResFile = this->UseTopicResFile();
  596.         
  597.     if (this->HasBlurb())
  598.         test = this->BlurbRef()->Event(eventRec);
  599.  
  600.     ::UseResFile (oldResFile);
  601.     
  602.     return test;
  603. } // end Event
  604.  
  605.  
  606.  
  607.  
  608.  
  609. /*=============================== ABOtherTopic::Stop ================================*/
  610. OSErr    ABOtherTopic::Stop(void)
  611. {
  612.     OSErr    error = noErr;
  613.     
  614.     short        oldResFile = this->UseTopicResFile();
  615.     
  616.     error = this->CloseTopic();
  617.     
  618.     ::UseResFile (oldResFile);
  619.     
  620.     return error;
  621.     
  622. } // end Stop
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629. //    end of file
  630.  
  631.